package com.gemfire.onlineretailer.domain;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

import com.gemstone.gemfire.DataSerializable;

public class Furniture extends Item implements DataSerializable {

	  public static final long FURNITURE_1 = 10000001;
	  public static final long FURNITURE_2 = 10000002;

	  public static final long FURNITURE_3 = 10000003;
	  public static final long FURNITURE_4 = 10000004;
	  public static final long FURNITURE_5 = 10000005;
	  
	  public static final String FURNITURE_1_CODE = "10000001";
	  public static final String FURNITURE_2_CODE = "10000002";

	  public static final String FURNITURE_3_CODE = "10000003";
	  public static final String FURNITURE_4_CODE = "10000004";
	  public static final String FURNITURE_5_CODE = "10000005";
		  
	  public static final float FURNITURE_1_ORIGNAL_PRICE = 28.00f;
	  public static final float FURNITURE_2_ORIGNAL_PRICE = 30.00f ;
	  public static final float FURNITURE_3_ORIGNAL_PRICE = 32.00f;
	  public static final float FURNITURE_4_ORIGNAL_PRICE = 34.00f;
	  public static final float FURNITURE_5_ORIGNAL_PRICE = 36.00f;
	  
	private int furnitureType;
	private float length;
	private float width;
	private float hiight;
	private String color;
	private boolean wooden;
	private boolean steelMade;
	
	public Furniture(){
		super();
	}
	
	
	public int getFurnitureType() {
		return furnitureType;
	}

	public void setFurnitureType(int furnitureType) {
		this.furnitureType = furnitureType;
	}

	public float getLength() {
		return length;
	}

	public void setLength(float length) {
		this.length = length;
	}

	public float getWidth() {
		return width;
	}

	public void setWidth(float width) {
		this.width = width;
	}

	public float getHiight() {
		return hiight;
	}

	public void setHiight(float hiight) {
		this.hiight = hiight;
	}

	public String getColor() {
		return color;
	}

	public void setColor(String color) {
		this.color = color;
	}

	public boolean isWooden() {
		return wooden;
	}

	public void setWooden(boolean wooden) {
		this.wooden = wooden;
	}

	public boolean isSteelMade() {
		return steelMade;
	}

	public void setSteelMade(boolean steelMade) {
		this.steelMade = steelMade;
	}

	@Override
	public void fromData(DataInput in) throws IOException,
			ClassNotFoundException {
		this.furnitureType = in.readInt();
		this.length = in.readFloat();
		this.width = in.readFloat();
		this.hiight = in.readFloat();
		this.color = in.readUTF();
		this.wooden = in.readBoolean();
		this.steelMade = in.readBoolean();
		
	}

	@Override
	public void toData(DataOutput out) throws IOException {
		out.writeInt(this.furnitureType);
		out.writeFloat(this.length);
		out.writeFloat(this.width);
		out.writeFloat(this.hiight);
		out.writeUTF(this.color);
		out.writeBoolean(this.wooden);
		out.writeBoolean(this.steelMade);
		
	}
	
public static Furniture createInstance(long furnitureId){
		
		/*
		 * Use itemId to read from DB or from other source, Hardcode for now
		 */
		
	Furniture furniture = new Furniture();
		
		if (furnitureId == FURNITURE_1){
			furniture.setItemId(FURNITURE_1);
			furniture.setFurnitureType(FurnitureType.DINING_TABLE.getCode());
			furniture.setItemCode(FURNITURE_1_CODE);
			furniture.setItemName("Diniing Table");
		} 
		else if (furnitureId == FURNITURE_2){
			furniture.setItemId(FURNITURE_2);
			furniture.setFurnitureType(FurnitureType.BED.getCode());
			furniture.setItemCode(FURNITURE_2_CODE);
			furniture.setItemName("Kingsize Bed");
		} 
		else if (furnitureId == FURNITURE_3){
			furniture.setItemId(FURNITURE_3);
			furniture.setFurnitureType(FurnitureType.SOFA.getCode());
			furniture.setItemCode(FURNITURE_3_CODE);
			furniture.setItemName("Sofa");
		} 
		else if (furnitureId == FURNITURE_4){
			furniture.setItemId(FURNITURE_4);
			furniture.setFurnitureType(FurnitureType.TV_STAND.getCode());
			furniture.setItemCode(FURNITURE_4_CODE);
			furniture.setItemName("Tv Stand");
		}
		else {
			furniture.setItemId(FURNITURE_5);
			furniture.setFurnitureType(FurnitureType.DINING_CHAIR.getCode());
			furniture.setItemCode(FURNITURE_5_CODE);
			furniture.setItemName("Dining Chair");
	
			} 
		
		return furniture;
		
	}


}
